package cn.yunhe.controller;

import cn.yunhe.entity.Department;
import cn.yunhe.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.servlet.http.HttpSession;
import java.beans.MethodDescriptor;
import java.util.List;

@RestController
public class DepartmentController {

    @Autowired
    @Qualifier("departmentService")
    private DepartmentService departmentService;

    @RequestMapping("/selectalldep")
    public String selectAllDep(HttpSession session){
        List<Department> departments =  departmentService.selectAllDep();
        session.setAttribute("departments",departments);
        return "redirect:register.html";
    }
//    @RequestMapping("/selectalldep2")
//    public ModelAndView selectAllDep2(HttpSession session){
//        ModelAndView mv = new ModelAndView();
//        List<Department> departments =  departmentService.selectAllDep();
//        mv.addObject("departments",departments);
//        mv.setView(new MappingJackson2JsonView());
//        mv.setViewName("/register.html");
//        return mv;
//    }

    @RequestMapping("/selectalldep2")
    public List<Department> selectAllDep2(){
        List<Department> departments =  departmentService.selectAllDep();
        return departments;
    }


}
